package com.study.designpattern.factory;

public class AbstractFactoryTest {
    public static void main(String[] args) {
        IDatabaseUtils databaseUtils=new MysqlDatabase();
        IConnection connection = databaseUtils.getConnection();
        connection.Connection();
        ICommand command = databaseUtils.getCommand();
        command.Command();
    }
}
//描述：数据库有mysql，oracle，分别有不同的connection，command.
//接口声明：
interface IConnection{
   void Connection();
}
interface ICommand{
    void Command();
}
//接口实现抽象
interface IDatabaseUtils{
    IConnection getConnection();
    ICommand getCommand();
}
//抽象类实现
abstract class IDataBase{
    abstract IConnection getConnection();
    abstract ICommand getICommand();
}
//Mysql
class MysqlConnection implements IConnection{
    @Override
    public void Connection() {
        System.out.println("Mysql connected!");
    }
}
class MysqlCommand implements ICommand{
    @Override
    public void Command() {
        System.out.println("Mysql command.");
    }
}
class MysqlDatabase implements IDatabaseUtils{
    @Override
    public IConnection getConnection() {
        return new MysqlConnection();
    }

    @Override
    public ICommand getCommand() {
        return new MysqlCommand();
    }
}
class MysqlData extends IDataBase{
    @Override
    IConnection getConnection() {
        return new MysqlConnection();
    }

    @Override
    ICommand getICommand() {
        return new MysqlCommand();
    }
}
//Oracle
class OracleConnection implements IConnection{
    @Override
    public void Connection() {
        System.out.println("Oracle connected!");
    }
}
class OracleCommand implements ICommand{
    @Override
    public void Command() {
        System.out.println("Oracle command.");
    }
}
class OracleDatabase implements IDatabaseUtils{
    @Override
    public IConnection getConnection() {
        return new OracleConnection();
    }

    @Override
    public ICommand getCommand() {
        return new OracleCommand();
    }
}
class OracleData extends IDataBase{
    @Override
    IConnection getConnection() {
        return new OracleConnection();
    }

    @Override
    ICommand getICommand() {
        return new OracleCommand();
    }
}
